package kingAI.calc.util;

/**
 * Contains basic combinatorics operations.
 * 
 * @author Equilibrium
 * @version 1.0
 */
public class Combinatorics {
	/**
	 * Calculates C(up,down).
	 * 
	 * @param up N in C(N,K).
	 * @param down K in C(N,K).
	 * @return C(up,down)
	 */
	public static int combination(int up, int down){
		int result=1,div=2;
		for(int i=down+1;i<=up;i++){
			result*=i;
			for(;div<=up-down && result%div==0;div++)
				result/=div;
		}
		return result;
	}
}
